/**
 * 
 */
package unitTests;
import pieces.*;
import mainClasses.*;

import junit.framework.TestCase;

/**
 * @author sbalasu3
 *
 */
public class KingTest extends TestCase {

	Board board = new Board();
	/**
	 * @param name
	 */
	public KingTest(String name) {
		super(name);
	}

	/* 
	 * @see junit.framework.TestCase#setUp()
	 */
	protected void setUp() throws Exception {
		Pawn pawn1 = new Pawn(5,6,board, "White");
		board.add(pawn1);
		Pawn pawn2 = new Pawn(4,5,board, "Black");
		board.add(pawn2);
		super.setUp();
	}

	/* 
	 * @see junit.framework.TestCase#tearDown()
	 */
	protected void tearDown() throws Exception {
		super.tearDown();
	}

	/**
	 * Test method for {@link pieces.King#movePossible(java.awt.Point)}.
	 */
	public void testMovePossible() {
		King king = new King(5,5,board, "White");
		board.add(king);
		assertFalse(king.movePossible(5,7)); //should return false since king can't move more than one block
		assertFalse(king.movePossible(5,3));
		assertFalse(king.movePossible(0,5));
		assertFalse(king.movePossible(7,7));
		assertFalse(king.movePossible(5,6));	//should return false since there is a white pawn at that location.
		assertTrue(king.movePossible(5,4));	//should return true since there is a black pawn at that location and it is a enemy of this piece.
		assertTrue(king.movePossible(4,5));	//should return true since king can move one block up down right left and in diagonal
		assertTrue(king.movePossible(6,5));
		assertTrue(king.movePossible(6,6));
		assertTrue(king.movePossible(4,6));
		assertTrue(king.movePossible(4,4));
		assertTrue(king.movePossible(4,6));
	}

	/**
	 * Test method for {@link pieces.Piece#isEnemy(java.awt.Point)}.
	 */
	public void testIsEnemy() {
		King king = new King(5,5,board, "White");
		board.add(king);
		King king2 = new King(6,6,board, "Black");
		board.add(king2);
		King king3 = new King(6,7,board, "White");
		board.add(king3);
		assertTrue(king.isEnemy(6,6));	//true since king2 is an enemy of king
		assertFalse(king.isEnemy(6,7));//false since king is not an enemy of king
	}

	/**
	 * Test method for {@link pieces.Piece#getX()}.
	 */
	public void testGetX() {
		King king = new King(5,7,board, "White");
		board.add(king);
		assertTrue(king.getX()==5); //true since the x value is 5
	}

	/**
	 * Test method for {@link pieces.Piece#getY()}.
	 */
	public void testGetY() {
		King king = new King(5,7,board, "White");
		board.add(king);
		assertTrue(king.getY()==7); //true since the y value is 7
	}

	
	

	/**
	 * Test method for {@link pieces.Piece#getType()}.
	 */
	public void testGetType() {
		King king = new King(5,7,board, "White");
		board.add(king);
		assertTrue(king.getType().equals("   King  ")); //true since its a white king so the type is   King
		King king2 = new King(7,7,board, "Black");
		board.add(king2);
		assertTrue(king2.getType().equals("BK-->King")); //true since its a white king so the type is BK-->King
	}

	/**
	 * Test method for {@link pieces.Piece#getSide()}.
	 */
	public void testGetSide() {
		King king = new King(5,7,board, "White");
		board.add(king);
		assertTrue(king.getSide().equals("White")); //should be true since it's a white piece
		King king2 = new King(7,7,board, "Black");
		board.add(king2);
		assertTrue(king2.getSide().equals("Black")); //should be true since it's a black piece
	}

	/**
	 * Test method for {@link pieces.Piece#setType(java.lang.String)}.
	 */
	public void testSetType() {
		King king = new King(5,7,board, "White");
		king.setType("Random Side");
		assertTrue(king.getType().equals("Random Side")); //should return true since i set the Type to Random Side
	}

	/**
	 * Test method for {@link pieces.Piece#isEqual(pieces.Piece)}.
	 */
	public void testIsEqual() {
		King king = new King(5,7,board, "White");
		board.add(king);
		King king2 = new King(7,7,board, "Black");
		board.add(king2);
		assertTrue(king.isEqual(king));	//should be equal since they are both the same.
		assertFalse(king.isEqual(king2));	//should be false since they are different
	}

	/**
	 * Test method for {@link pieces.Piece#move(java.awt.Point)}.
	 */
	public void testMove() {
		King king = new King(5,5,board, "White");
		board.add(king);
		King king2 = new King(0,0,board, "Black");
		board.add(king2);
		
		king.move(5,7);								//shouldn't be able to move there since more than two blocks
		assertTrue(king.getX() == 5);
		assertTrue(king.getY() == 5);
		
		 
		king.move(5,3);
		assertTrue(king.getX() == 5);
		assertTrue(king.getY() == 5);
		
		
		king.move(0,5);
		assertTrue(king.getX() == 5);
		assertTrue(king.getY() == 5);
		
		
		king.move(7,7);
		assertTrue(king.getX() == 5);
		assertTrue(king.getY() == 5);
		
		
		king.move(5,6);
		assertTrue(king.getX() == 5);
		assertTrue(king.getY() == 5);
		
		
		king.move(5,4);													//should be able to move since the piece there is an enemy piece
		assertTrue(king.getX() == 5);
		assertTrue(king.getY() == 4);
		king.move(5,5);
			
		king.move(4,5);											//should be able to move since they are only one block moves and no pieces are blocking them
		assertTrue(king.getX() == 4);					
		assertTrue(king.getY() == 5);
		king.move(5,5);
		
		king.move(6,5);
		assertTrue(king.getX() == 6);					
		assertTrue(king.getY() == 5);
		king.move(5,5);
		
		king.move(6,6);
		assertTrue(king.getX() == 6);					
		assertTrue(king.getY() == 6);
		king.move(5,5);
		
		king.move(4,6);
		assertTrue(king.getX() == 4);					
		assertTrue(king.getY() == 6);
		king.move(5,5);
		
		king.move(4,4);
		assertTrue(king.getX() == 4);					
		assertTrue(king.getY() == 4);
		king.move(5,5);
		
		king.move(4,6);
		assertTrue(king.getX() == 4);					
		assertTrue(king.getY() == 6);
		
	}

	/**
	 * Test method for {@link pieces.Piece#changePosition(java.awt.Point)}.
	 */
	public void testChangePosition() {
		King king = new King(5,5,board, "White");
		board.add(king);
		king.changePosition(10, 10);
		assertTrue(king.getX() == 10);					//should return true since we set the location of the king to Point(10, 10)
		assertTrue(king.getY() == 10);					//should return true since we set the location of the king to Point(10, 10)
		
	}

}
